From 2e520bb87bfd6803f44a840ec87e099b1785e364 Mon Sep 17 00:00:00 2001 From: "laudney@eclipse.(none)" Date: Thu, 13 Nov 2003 12:25:31 +0000 Subject: [PATCH] bitkeeper revision 1.599 (3fb3783bCzU2OI0iS1r2i_GVLKRG0Q) Fixes. Xen console buffer ring can be cleared at request. --- tools/internal/xi_read_console_ring.c | 29 +++++++++++++++++++-------- xen/common/console.c | 13 ++++++------ xen/common/dom0_ops.c | 5 +++-- xen/include/hypervisor-ifs/dom0_ops.h | 1 + xen/include/xeno/console.h | 11 +++++++--- 5 files changed, 39 insertions(+), 20 deletions(-) diff --git a/tools/internal/xi_read_console_ring.c b/tools/internal/xi_read_console_ring.c index eaa73aed92..b8ddf0695f 100644 --- a/tools/internal/xi_read_console_ring.c +++ b/tools/internal/xi_read_console_ring.c @@ -4,10 +4,12 @@ #include "dom0_defs.h" -#define CONSOLE_RING_SIZE 16392 +#define CONSOLE_RING_SIZE 16392 +#define CONSOLE_RING_CLEAR 1 + static char *argv0 = "read_console_ring"; -static long read_console_ring(unsigned long str, unsigned count) +static long read_console_ring(unsigned long str, unsigned count, unsigned int cmd) { int ret; dom0_op_t op; @@ -15,6 +17,7 @@ static long read_console_ring(unsigned long str, unsigned count) op.cmd = DOM0_READCONSOLE; op.u.readconsole.str = str; op.u.readconsole.count = count; + op.u.readconsole.cmd = cmd; ret = do_dom0_op(&op); if (ret > 0) { @@ -26,22 +29,32 @@ static long read_console_ring(unsigned long str, unsigned count) int main(int argc, char **argv) { - char str[CONSOLE_RING_SIZE]; - + char str[CONSOLE_RING_SIZE+1]; + unsigned int cmd = 0; + if ( argv[0] != NULL ) argv0 = argv[0]; - if ( argc > 2) { - fprintf(stderr, "Usage: %s [-r]\n", argv0); + if ( argc > 2 || (argc == 2 && strcmp(argv[1], "-c")) ) { + fprintf(stderr, "Usage: %s [-c]\n", argv0); + return 1; + } + + if ( argc == 2) { + cmd |= CONSOLE_RING_CLEAR; + } + + if ( mlock(str, CONSOLE_RING_SIZE+1) != 0) { + PERROR("Could not lock memory for user space read console ring buffer"); return 1; } - if ( read_console_ring((unsigned long)str, CONSOLE_RING_SIZE) < 0 ) { + if ( read_console_ring((unsigned long)str, CONSOLE_RING_SIZE, cmd) < 0 ) { printf("Read console ring error.\n"); - printf("%s", str); return 1; } printf("%s", str); + return 0; } diff --git a/xen/common/console.c b/xen/common/console.c index f6e3f250bb..d52a8cf3be 100644 --- a/xen/common/console.c +++ b/xen/common/console.c @@ -12,19 +12,18 @@ console_ring_t console_ring = { .len = 0 }; -void init_console_ring() -{ - console_ring.len = 0; -} - -long read_console_ring(unsigned long str, unsigned int count) +long read_console_ring(unsigned long str, unsigned int count, unsigned cmd) { unsigned int len; - len = (console_ring.len < count)? console_ring.len : count; + len = (console_ring.len < count) ? console_ring.len : count; if ( copy_to_user((char *)str, console_ring.buf, len) ) return -EFAULT; + if ( cmd & CONSOLE_RING_CLEAR ) { + console_ring.len = 0; + } + return len; } diff --git a/xen/common/dom0_ops.c b/xen/common/dom0_ops.c index 0558a1e40b..8db4b5fedb 100644 --- a/xen/common/dom0_ops.c +++ b/xen/common/dom0_ops.c @@ -415,9 +415,10 @@ long do_dom0_op(dom0_op_t *u_dom0_op) case DOM0_READCONSOLE: { - extern long read_console_ring(unsigned long, unsigned int); + extern long read_console_ring(unsigned long, unsigned int, unsigned int); ret = read_console_ring(op.u.readconsole.str, - op.u.readconsole.count); + op.u.readconsole.count, + op.u.readconsole.cmd); } break; diff --git a/xen/include/hypervisor-ifs/dom0_ops.h b/xen/include/hypervisor-ifs/dom0_ops.h index 770305f6ac..2c3d12ab78 100644 --- a/xen/include/hypervisor-ifs/dom0_ops.h +++ b/xen/include/hypervisor-ifs/dom0_ops.h @@ -194,6 +194,7 @@ typedef struct dom0_readconsole_st { unsigned long str; unsigned int count; + unsigned int cmd; } dom0_readconsole_t; typedef struct dom0_op_st diff --git a/xen/include/xeno/console.h b/xen/include/xeno/console.h index 589754d08a..375c4b2215 100644 --- a/xen/include/xeno/console.h +++ b/xen/include/xeno/console.h @@ -6,6 +6,9 @@ * Copyright (c) 2003 James Scott, Intel Research Cambridge */ +#ifndef __CONSOLE_H__ +#define __CONSOLE_H__ + /* * Ownership of console --- currently hardwired to dom0. This is used to see * who gets the PS/2 keyboard/mouse events @@ -43,7 +46,8 @@ extern int opt_console; -#define CONSOLE_RING_SIZE 16392 +#define CONSOLE_RING_SIZE 16392 +#define CONSOLE_RING_CLEAR 1 typedef struct console_ring_st { @@ -53,5 +57,6 @@ typedef struct console_ring_st extern console_ring_t console_ring; -void init_console_ring(); -long read_console_ring(unsigned long, unsigned int); +long read_console_ring(unsigned long, unsigned int, unsigned int); + +#endif -- 2.30.2